#include <stdio.h>
#include <string.h>
#include <stdlib.h>


//代码有问题


int getpalindrome(int str)
{
    int num = str;
    int add = 0;
    while (str > 0)
    {
        int idx = str % 10;   // 得出尾数
        add = add * 10 + idx; // 让上一轮的数乘10,然后加上这一轮得出的尾数
        str /= 10;            // 去掉尾数循环下一轮
    }

    return add == str;
}

char* StringAddition(char *num1, char *num2)
{
    int length1 = strlen(num1);
    int length2 = strlen(num2);

    /*三日运算符*/
    int maxLength = length1 > length2 ? length1 : length2;
    int val1 = atoi(num1);
    int val2 = atoi(num2);

    int sum = val1 + val2;
    /*得到逆序数 */
    int reverseNum = getpalindrome(sum);

    char *str = (char *)malloc(sizeof(char) * (maxLength + 1));

    if (str == NULL)
    {
        return NULL;
    }

    /* 清除脏数据 */
    memset(str, 0, sizeof(char) * (maxLength + 1));

    int pos = 0;
    while (reverseNum)
    {
        str[pos] = reverseNum % 10 + '0';
        reverseNum = reverseNum / 10;
        pos++;
    }
    return str;
}

int main()
{
    char *val1 = "123";
    char *val2 = "123";

    char *sumStr = StringAddition(val1, val2);
    printf("sumstr =%s\n", sumStr);

    return 0;
}